# Arguments in the following format:
# param: keyStore password

WLP_HOME=/opt/IBM/Liberty/8.5.5.1/wlp

# Process command line arguments
args=($@)   

cd $WLP_HOME/usr/servers/defaultServer

# Stop Liberty Server
echo "Stop Liberty Server ......"
service libertyservice stop

linenum=`grep -n "Enable new feature" server.xml | cut -d: -f1`
echo "Insert new feature SSL-2.0 for WLP at $linenum line"
`sed -i ''$linenum' a <feature>ssl-2.0</feature>\n' $WLP_HOME/usr/servers/defaultServer/server.xml`


linenum=`grep -n "Enable new configuration" server.xml | cut -d: -f1`
echo "Insert new configuration of keyStore for WLP to enable SSL at $linenum line"
`sed -i ''$linenum' a <keyStore id="defaultKeyStore" location="ihsserverkdb.jks" type="JKS" password="'${args[0]}'"/>\n' $WLP_HOME/usr/servers/defaultServer/server.xml`

echo "Copy ssl key to WLP server ......"
`cp /tmp/ihsserverkdb.jks $WLP_HOME/usr/servers/defaultServer/resources/security`

# Start Liberty Server
echo "Start Liberty Server ......"
service libertyservice start 

